package com.unionx.unionxuf.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unionx.unionxuf.entity.Code;
import com.unionx.unionxuf.entity.ReceivepayManger;
import com.unionx.unionxuf.localdao.ReceivepayMangerMapper;
import com.unionx.unionxuf.service.LocalReceivepayManagerService;
import com.unionx.unionxuf.service.SubjectBindService;



@Controller
@RequestMapping(value="/rm")
public class LocalReceivepayManager {
	
	@Autowired(required=true)
	private LocalReceivepayManagerService rmms;
	@Autowired(required = true)
	private SubjectBindService subjectService;
	

	@RequestMapping(value="/insert/receivepay")
	@ResponseBody
	public Object  insertReceivepay(String sde,String st,String sb,String sn,String cropid){
		
	
		
		Map<String,Object> map =  new HashMap<String,Object>();
		int k=0;
		
		String str1[] =sde.split(",");
		String str2[] =st.split(",");
		String str3[] =sb.split(",");
		String str4[] =sn.split(",");
		
		if(str1.length>1){
			for(int i=0;i<str1.length;i++){
				
				int type=0;
				if(str1[i].equals("应收")){
					type=1;
				}
				if(str1[i].equals("应付")){
					type=0;
				}
				
				ReceivepayManger r = new ReceivepayManger();
				r.setType(type);
				r.setCorp(str2[i]);
				r.setSubjectcode(str3[i]);
				r.setSubjectname(str4[i]);
				r.setCorpid(cropid);
				
				k=	rmms.insertReceivepay(r);
			}
			
		}else{

			int type=0;
			if(str1[0].equals("应收")){
				type=1;
			}
			if(str1[0].equals("应付")){
				type=0;
			}
			
			ReceivepayManger r = new ReceivepayManger();
			r.setType(type);
			r.setCorp(str2[0]);
			r.setSubjectcode(str3[0]);
			r.setSubjectname(str4[0]);
			r.setCorpid(cropid);
			k=	rmms.insertReceivepay(r);
		}
		
		map.put("status", k);
		return  map;
	}
	
	@RequestMapping(value="/del")
	@ResponseBody
	public Object  delReceivepay(String buytype,String corp,String cropid){
		int type=0;
		if(buytype.equals("应收")){
			type=1;
		}
		if(buytype.equals("应付")){
			type=0;
		}
		ReceivepayManger r = new ReceivepayManger();
		r.setType(type);
		r.setCorp(corp);
		r.setCorpid(cropid);
		return rmms.delReceivepay(r);
	}
	
	@RequestMapping(value="/crp")
	@ResponseBody
	public Object  findType(String buytype,String cropid){
		//应收 1
		int  type=0;
		if(buytype.equals("应收")){
			type=1;
		};
		if(buytype.equals("应付")){
			type=0;
		}
		ReceivepayManger r = new ReceivepayManger();
		r.setType(type);
		r.setCorpid(cropid);
		return rmms.findType(r);
	}
	
	
	@RequestMapping(value="/selectrm")
	@ResponseBody
	public Object  selectrm(String cropid){
		
		
		return rmms.selectrm(cropid);
	}		
	
}
